#coding:utf8
#
# Author: CMGS
# Created on 2010-10-9
#

import time
import traceback
from common import config as _config
from ext.logger import Logger as _Logger

class Debugger(object):
    
    @classmethod
    def init(cls):
        cls.logger = _Logger()
    
    @classmethod
    def out(cls, *c):
        if _config.DEBUG:
            for v in c:
                print v
            return True
        cls.logger.record('info', time.time(), ' '.join(c))

    @classmethod
    def exc(cls, e):
        if _config.DEBUG:
            print traceback.format_exc()
            return True
        cls.logger.record('error', time.time(), e.message)

if __name__ == '__main__':
    Debugger.init()
    for i in range(0, 10):
        Debugger.out('xxoo ' + str(i))
        try:
            1/0
        except Exception, e:
            Debugger.exc(e)
